package Controler;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import Information.Enterprise;
import Information.UserInfo;
import Model.EnterpriseDAO;
import Model.UserInfomrmationDAO;

public class manageEnterprise extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public manageEnterprise() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		ArrayList<Enterprise> enterpriseArrayList = new ArrayList<Enterprise>();
		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		String EUser = null;
		String EPassword = null;
		String EEmail = null;
		String EName = null;
		EnterpriseDAO enterprisedao = new EnterpriseDAO();
		try {
			enterpriseArrayList = enterprisedao.SeeAllEnterprise();
		} catch (ClassNotFoundException | SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		String result = "";
		for(Enterprise enterprise : enterpriseArrayList)
		{
			result+="<div class='panel panel-primary'>";
			result+="<form role='form' id='EnterpriseForm' method='post' action='updateCVNow'>";
			result+="<div class='form-group' id='EUserDiv'><label for='EUser'>企业用户名</label><input type='text' class='form-control' id='EUser' name='EUser' value='"+enterprise.getEUser()+"' disabled></div>";
			result+="<div class='form-group' id='EPasswordDiv'><label for='EPassword'>密码</label><input type='text' class='form-control' id='EPassword' name='EPassword' value='"+enterprise.getEPassword()+"'></div>";
			result+="<div class='form-group' id='ENameDiv'><label for='EName'>企业名</label><input type='text' class='form-control' id='EName' name='EName' value='"+enterprise.getEName()+"'></div>";
			result+="<div class='form-group' id='EEmailDiv'><label for='EEmail'>企业邮箱</label><input type='text' class='form-control' id='EEmail' name='EEmail' value='"+enterprise.getEEmail()+"'></div>";
			result+="<div class='form-group' id='EAddressDiv'><label for='EAddress'>企业地址</label><input type='text' class='form-control' id='EAddress' name='EAddress' value='"+enterprise.getEAddress()+"'></div>";
			result+="<div class='form-group' id='updateDiv'><a class='btn btn-success' id='updateEnterprise' type='button'>更新</a></div>";
			result+="<div class='form-group' id='deleteDiv'><a class='btn btn-danger' id='deleteEnterprise' type='button'>删除</a></div></form></div>";
		}
		out.println(result);
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occurs
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}
